package com.example.myapplication.ui.upload

import com.example.myapplication.ui.FileBean
/**
 * 局部更新的FileUploadBean表Card
 */
class FileUploadCard  {

    companion object{
        fun createFileUploadCard(bean : FileUploadBean) :FileUploadCard{
            val stateValue = if (!bean.state.startsWith(FileBean.STATE_DEFAULT_FLAG)) {
                FileUploadBean.UPLOAD_ERROR
            } else {
                if (bean.uploadSize < bean.length) {
                    FileUploadBean.UPLOAD_RUNNING
                } else if (bean.uploadSize == bean.length) {
                    FileUploadBean.UPLOAD_FINISH
                } else {
                    FileUploadBean.UPLOAD_ERROR
                }
            }
            return FileUploadCard(bean.id, bean.uploadSize, stateValue, bean.state, bean.updateAt)
        }

        fun createFileUploadCard(id: Int, uploadSize: Long, fileSize: Long, state: String) :FileUploadCard{
            val stateValue = if (!state.startsWith(FileBean.STATE_DEFAULT_FLAG)) {
                FileUploadBean.UPLOAD_ERROR
            } else {
                if (uploadSize < fileSize) {
                    FileUploadBean.UPLOAD_RUNNING
                } else if (uploadSize == fileSize) {
                    FileUploadBean.UPLOAD_FINISH
                } else {
                    FileUploadBean.UPLOAD_ERROR
                }
            }
            return FileUploadCard(id, uploadSize, stateValue, state, System.currentTimeMillis())
        }

    }

    val uploadSize: Long

    val uploadState: Byte

    val state: String

    val updateAt:Long

    val id: Int

    constructor(id: Int, uploadSize: Long, uploadState: Byte, state: String, updateAt: Long) {
        this.id = id
        this.uploadSize = uploadSize
        this.uploadState = uploadState
        this.state = state
        this.updateAt = updateAt
    }
}